<template>
  <div class="inHospitalManage">
    <div class="record">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column label="操作" width="200">
          <template slot-scope="scope">
            <el-link type="primary" @click="inHospital(scope.row)">办理入科</el-link>
          </template>
        </el-table-column>
        <el-table-column prop="patientId" label="用户id"></el-table-column>
        <el-table-column prop="departmentId" label="科室">
          <template slot-scope="scope">
            <span>{{ getDepartmentName(scope.row.departmentId) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="sex" label="性别"></el-table-column>
        <el-table-column prop="patientName" label="用户姓名"></el-table-column>
        <el-table-column prop="phoneNumber" label="手机号码"></el-table-column>
        <el-table-column prop="idNumber" label="身份证号码"></el-table-column>
        <el-table-column prop="inquiryDesc" label="备注"></el-table-column>
      </el-table>
      <div class="page">
        <el-pagination
          align="right"
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageIndex"
          :page-sizes="[5, 10]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next"
          :total="totalNumber"
          style="margin-top: 58px; margin-bottom: 40px"
        ></el-pagination>
      </div>
      <el-dialog title="病床分配" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
        <el-form ref="form1" label-width="80px">
          <el-form-item label="病床列表">
            <el-select v-model="sickBedId" placeholder="请选择">
              <el-option
                v-for="item in sickBedList"
                :key="item.sickBedId"
                :label="item.sickBedName"
                :value="item.sickBedId"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-form>

        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible3 = false">取 消</el-button>
          <el-button type="primary" @click="formConfirm">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
export default {
  name: "inHospitalManage",
  props: {
    adminName: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      recordId: 0,
      tableData: [],
      sickBedList: [
        {
          value: "选项1",
          label: "黄金糕"
        },
        {
          value: "选项2",
          label: "双皮奶"
        },
        {
          value: "选项3",
          label: "蚵仔煎"
        },
        {
          value: "选项4",
          label: "龙须面"
        },
        {
          value: "选项5",
          label: "北京烤鸭"
        }
      ],
      departmentList: [],
      dialogVisible: false,
      sickBedId: "",
      pageIndex: 1,
      pageSize: 10,
      totalNumber: 100
    };
  },
  created() {
    this.getInHospitalList();
    this.getDepartmentList();
  },
  methods: {
    getInHospitalList() {
      let params = {
        pageIndex: 1,
        pageSize: 10
      };
      this.$axios
        .get("/api/CjwPatient/GetInHospitalList", { params })
        .then(res => {
          this.tableData = res.data.getPatientRecordListDto;
        });
    },
    getDepartmentList() {
      // console.log(111);
      this.$axios.get("/api/CjwDepartment/GetDepartmentList").then(res => {
        this.departmentList = res.data;
        console.log(this.departmentList);
      });
    },
    getDepartmentName(id) {
      let departmentName = "";
      this.departmentList.forEach(i => {
        if (i.departmentId == id) {
          departmentName = i.departmentName;
        }
      });
      return departmentName;
    },
    inHospital(item) {
      this.dialogVisible = true;
      this.recordId = item.recordId;
      console.log(item);
      this.$axios
        .post(
          "/api/CjwPatient/GetSickBedsByDepartmentId?departmentId=" +
            item.departmentId
        )
        .then(res => {
          this.sickBedList = res.data;
        });
    },
    handleClose() {
      this.dialogVisible = false;
    },
    formConfirm() {
      let params = {
        recordId: this.recordId,
        sickBedId: this.sickBedId,
        nurseId: this.adminName,
        state: 5
      };
      console.log(params);
      this.$axios.post("/api/CjwPatient/InSickBed", params).then(res => {
        this.$message({
          type: "success",
          message: "入科成功"
        });
      });
      this.getInHospitalList();
      this.dialogVisible = false;
      let op = {
        opAdminName: this.adminName,
        opTable: "入科",
        opData: `记录id:${params.recordId}病床id:${params.sickBedId}`
      };
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getInHospitalList();
    },
    handleCurrentChange(val) {
      this.pageIndex = val;
      this.getInHospitalList();
    }
  }
};
</script>

<style scoped>
.page {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
}
</style>